home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Essentials / AppleScanGS / Event.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-23  |  6.4 KB  |  229 lines  |  [TEXT/MPS ]

  1. /**********************************************************************
  2. *
  3. * Event.c
  4. *
  5. * Copyright (c)
  6. * Apple Computer, Inc.  1986-1989
  7. * All Rights Reserved.
  8. *
  9. * This file contains the code which implements the 
  10. * main event loop used by the scanner program.
  11. *
  12. **********************************************************************/
  13.  
  14. #include <types.h>
  15. #include <locator.h>
  16. #include <quickdraw.h>
  17. #include <event.h>
  18. #include <menu.h>
  19. #include <window.h>
  20. #include "Scan.h"
  21.  
  22. extern WmTaskRec        event;
  23. extern unsigned int     quitFlag;
  24. extern GrafPortPtr    previewWindowPtr;
  25. extern GrafPortPtr    settingsWindowPtr;
  26. static GrafPortPtr  lastWindow;         /* This private global is used in checkFrontW()
  27.                                         ** to prevent extra work when the windows
  28.                                         ** have not changed.  It is initialized
  29.                                         ** at the beginning of mainEvent().
  30.                                         */
  31.  
  32. /**********************************************************************
  33. *
  34. * doSetPageScroll
  35. *
  36. * This procedure is called when an inGrow or inZoom message is returned
  37. * by TaskMaster.
  38. *
  39. * This procedure resets the values used to scroll the content region
  40. * when the page areas are clicked on in the scroll bars.
  41. *
  42. ***********************************************************************/
  43.  
  44. static void doSetPageScroll()
  45. {
  46.     int        tempH, tempV;
  47.     
  48.     tempV = lastWindow->portRect.v2-lastWindow->portRect.v1;    /* calculate vertical size */
  49.     tempH = lastWindow->portRect.h2-lastWindow->portRect.h1;    /* calculate width */
  50.     SetPage(tempH-10, tempV-10, lastWindow);
  51. }
  52.  
  53.  
  54. /**********************************************************************
  55. *
  56. * doControls
  57. *
  58. * This procedure is called when an inControl message is returned
  59. * by TaskMaster.
  60. *
  61. * When this routine gets control, the ID of the control that was
  62. * hit is in TaskDATA4.  The control handle is in TaskData2 and
  63. * the part code is in taskData 3.
  64. *
  65. **********************************************************************/
  66. void    doControls()
  67. {
  68.     LongWord    theID, thePartCode;
  69.     LongWord    theControlHandle;
  70.     
  71.     theID = event.wmTaskData4;
  72.     thePartCode = event.wmTaskData3;
  73.     theControlHandle = event.wmTaskData2;
  74.  
  75.     if (( 0 <= theID) && (theID <= 0xFFFFFFFF )) {
  76.         
  77.         switch(theID) {
  78.  
  79.             case    ScanButton:                
  80.                         doScanButton();
  81.                         break;
  82.  
  83.             case    PreviewButton:            
  84.                         doPreviewButton();
  85.                         break;
  86.  
  87.         }
  88.     }
  89. }
  90.  
  91.  
  92. /**********************************************************************
  93. *
  94. * doInContent
  95. *
  96. * This procedure is called when an InContent message is returned
  97. * by TaskMaster.
  98. *
  99. * When this routine gets control, the ID of the control that was
  100. * hit is in TaskDATA4.  The control handle is in TaskData2 and
  101. * the part code is in taskData 3.
  102. *
  103. **********************************************************************/
  104. void    doInContent()
  105. {
  106.     LongWord    theID, thePartCode;
  107.     LongWord    theControlHandle;
  108.     
  109.     
  110.     theID = event.wmTaskData4;
  111.     thePartCode = event.wmTaskData3;
  112.     theControlHandle = event.wmTaskData2;
  113.     
  114.     SelectWindow(event.wmTaskData);
  115.     
  116. #if 0
  117.     if (event.what == 0x01) {                        /* was it a mouse down event? */
  118.         if ((GrafPortPtr) event.wmTaskData == previewWindowPtr){
  119.             doInPreview(event.where);
  120.  
  121.         }
  122.     }
  123. #endif
  124. }
  125.  
  126.  
  127.  
  128. /**********************************************************************
  129. *
  130. * checkFrontW
  131. *
  132. * This routine checks the front window to see if any changes need
  133. * to be made to the menu items.
  134. *
  135. * We do this so that the edit items are only active when a desk
  136. * accessory is active.
  137. *
  138. **********************************************************************/
  139. void    checkFrontW()
  140. {
  141.     GrafPortPtr     theWindow;
  142.     extern int        cTable[], defCTable[];
  143.  
  144.     theWindow = FrontWindow();
  145.         /* Get the front window into local storage.*/
  146.     
  147.     if (theWindow == lastWindow) return;
  148.         /* If the lastWindow is this window, we are all set. */
  149.     
  150.     /* If there are no windows, everything should be disabled */
  151.     if (!theWindow) {
  152.         SetMenuFlag(0x0080, EditMenuID);
  153.         HiliteMenu(0,EditMenuID);
  154.         SetColorTable(0,defCTable);
  155.     }
  156.  
  157.     /* if the front window is an image window, then we want to enable the edit items */
  158.     if (!( (theWindow == previewWindowPtr)||(theWindow == settingsWindowPtr))) {
  159.         EnableMItem(SaveAsID);    /* allow Save As... */
  160.         SetMenuFlag (0xFF7F, EditMenuID);       /* Set up for da windows. */
  161.         HiliteMenu(0,EditMenuID);
  162.     } else {
  163.         DisableMItem(SaveAsID);                    /* don't allow saving */
  164.         /* Otherwise we look at the window and see what to do. */
  165.         if (GetSysWFlag(theWindow)) { 
  166.             SetMenuFlag (0xFF7F, EditMenuID);       /* Set up for da windows. */
  167.              HiliteMenu(0,EditMenuID);
  168.         } else {
  169.             SetMenuFlag (0x0080, EditMenuID);       /* Set up for our windows. */
  170.              HiliteMenu(0,EditMenuID);
  171.         }
  172.     }
  173.  
  174.     /* use grayscale pallette for Preview or Image windows */
  175.     if((theWindow != settingsWindowPtr) && !GetSysWFlag(theWindow))
  176.         SetColorTable(0,cTable);
  177.     else
  178.         SetColorTable(0,defCTable);
  179.  
  180.     lastWindow = theWindow;     /* Remember this for next time. */
  181.     
  182.     /* here we want to update the hor/vert text if need be */
  183. }
  184.  
  185.  
  186.  
  187. /**********************************************************************
  188. *
  189. * mainEvent
  190. *
  191. * This is the main part of the program.  The program cycles in this
  192. * loop until the user choose select.
  193. *
  194. **********************************************************************/
  195. void    mainEvent()
  196. {
  197.     unsigned int    code;
  198.     unsigned        temp;
  199.  
  200.     event.wmTaskMask = 0x001FFF7F;          /* Allow TaskMaster to do everything, and return inContents   */
  201.     quitFlag         = 0;                   /* Done flag will be set by Quit item.  */
  202.     lastWindow       = NULL;                /* Init this for checkFrontW().         */
  203.  
  204.     for (;;) {
  205.         checkFrontW();
  206.         code = TaskMaster(0xFFFF, &event);
  207.         switch(code) {
  208.             case wNoHit:    /* null event, but TaskMaster might have handled something */
  209.                 temp = event.wmTaskData & 0xffff;    /* get the event code */
  210.                 if(temp == wInGrow || temp == wInZoom)    /* if the window changed sizes */
  211.                     doSetPageScroll();
  212.                 break;
  213.             case wInGoAway:
  214.                 doCloseTop();
  215.                 break;
  216.             case wInSpecial:
  217.             case wInMenuBar:
  218.                 doMenu();
  219.                 break;
  220.             case wInControl:
  221.                 doControls();
  222.                 break;
  223.             case wInContent:
  224.                 doInContent();
  225.                 break;
  226.         }
  227.         if (quitFlag) break;
  228.     }
  229. }